package cn.jhc.DaoImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import cn.jhc.DAO.ShopCarDao;
import cn.jhc.model.ShopCar;
import cn.jhc.model.User;

@Repository
public class ShopCarImpl implements ShopCarDao {

	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
    @Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	@Override
	public void addShopCar(ShopCar shopCar) {
	     Session session=sessionFactory.getCurrentSession();
         session.save(shopCar);
	}

	

	@Override
	public ShopCar findShopCarById(Integer id) {
		 Session session= sessionFactory.getCurrentSession();
		 ShopCar shopCar = (ShopCar) session.get(ShopCar.class, id);
		return shopCar;
	}

	@Override
	public List<ShopCar> findAllUser() {
		List<ShopCar> list=new ArrayList<ShopCar>();
		String sql="from shopcar";
		Session session=sessionFactory.getCurrentSession();
		list=(List<ShopCar>) session.createQuery(sql);
		return list;
	}

	@Override
	public void update(ShopCar shopCar) {
	   Session session=sessionFactory.getCurrentSession();
       session.update(shopCar);
	}

	@Override
	public void remove(ShopCar shopCar) {
		Session session=sessionFactory.getCurrentSession();
        session.delete(shopCar);
	}

}
